// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class PATIENT_OMN_O01 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("9 PID",9)]
  	    [HL7Field(HL7Version.v23, 9, HL7Repeat.False, HL7Required.True,"PID")]
	    public PID PID {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("11 PD1",11)]
  	    [HL7Field(HL7Version.v23, 11, HL7Repeat.False, HL7Required.False,"PD1")]
	    public PD1 PD1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("15 NTE",15)]
  	    [HL7Field(HL7Version.v23, 15, HL7Repeat.True, HL7Required.False,"NTE")]
	    public NTE[] NTE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("18 PATIENT_VISIT",18)]
  	    [HL7Field(HL7Version.v23, 18, HL7Repeat.False, HL7Required.False,"PATIENT_VISIT_OMN_O01")]
	    public PATIENT_VISIT_OMN_O01 PATIENT_VISIT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("24 INSURANCE",24)]
  	    [HL7Field(HL7Version.v23, 24, HL7Repeat.False, HL7Required.False,"INSURANCE_OMN_O01")]
	    public INSURANCE_OMN_O01 INSURANCE {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
			PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
			NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
			PATIENT_VISIT = ProcessGroup<PATIENT_VISIT_OMN_O01>(availableData, options, "PATIENT_VISIT");
			INSURANCE = ProcessGroup<INSURANCE_OMN_O01>(availableData, options, "INSURANCE");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isPID = availableData.StartsWith("PID", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PID", options.Version) || isPID) {
				return isPID;
			}
			bool isPD1 = availableData.StartsWith("PD1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PD1", options.Version) || isPD1) {
				return isPD1;
			}
			bool isNTE = availableData.StartsWith("NTE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NTE", options.Version) || isNTE) {
				return isNTE;
			}
			PATIENT_VISIT_OMN_O01 testPATIENT_VISIT_OMN_O01 = new PATIENT_VISIT_OMN_O01();
			bool grpCCPATIENT_VISIT_OMN_O01 = (testPATIENT_VISIT_OMN_O01.CanConsume(availableData, options));
			if (IsRequired("PATIENT_VISIT", options.Version) || grpCCPATIENT_VISIT_OMN_O01) {
				return grpCCPATIENT_VISIT_OMN_O01;
			}
			INSURANCE_OMN_O01 testINSURANCE_OMN_O01 = new INSURANCE_OMN_O01();
			bool grpCCINSURANCE_OMN_O01 = (testINSURANCE_OMN_O01.CanConsume(availableData, options));
			if (IsRequired("INSURANCE", options.Version) || grpCCINSURANCE_OMN_O01) {
				return grpCCINSURANCE_OMN_O01;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "PATIENT";
			}
        }

        static PATIENT_OMN_O01() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(PATIENT_OMN_O01));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PID != null) {
			string segmentValue = PID.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PD1 != null) {
			string segmentValue = PD1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (NTE != null && NTE.Length > 0) {
			for (int i = 0; i < NTE.Length; i++) {
				string segmentValue = NTE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (PATIENT_VISIT != null) {
			string segmentValue = PATIENT_VISIT.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (INSURANCE != null) {
			string segmentValue = INSURANCE.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

